from django.db import models

# Create your models here.
class Student(models.Model):
    SEX_CHOICES = {
        (0, '女'),
        (1, '男')
    }
    name = models.CharField('姓名', max_length=20)
    age = models.SmallIntegerField('年龄', null=True, blank=True)
    sex = models.SmallIntegerField('性别', choices=SEX_CHOICES)
    c_time = models.DateTimeField('创建时间', auto_now_add=True)
    u_time = models.DateTimeField('修改时间',auto_now=True)
    is_delete = models.BooleanField('逻辑删除',default=False)

    classes = models.ForeignKey('Classes', on_delete=models.SET_NULL, null=True, verbose_name='班级')


    def delete(self, using=None, keep_parents=False):
        self.is_delete = True
        self.save()   # 逻辑删除




class Classes(models.Model):
    name = models.CharField('班级名称', max_length=20, help_text='班级名称')
    num = models.CharField('班期', max_length=20,help_text='班期')
    c_time = models.DateTimeField('创建时间', auto_now_add=True)
    u_time = models.DateTimeField('修改时间', auto_now=True)
    is_delete = models.BooleanField('逻辑删除', default=False, help_text='逻辑删除')


    def delete(self, using=None, keep_parents=False):
        self.is_delete = True
        self.save()

    def __str__(self):
        return f'{self.name}-{self.num}'
